package com.yz.yrpc.config;

import org.springframework.beans.factory.FactoryBean;

import java.lang.reflect.Proxy;

/**
 * @author shanchong
 * @date 2019-06-30
 **/
public class RpcFactoryBean implements FactoryBean {

    private Class clazz;

    RpcFactoryBean(Class clazz){
        this.clazz = clazz;
    }

    @Override
    public Object getObject() throws Exception {
        Object o = Proxy.newProxyInstance(clazz.getClassLoader(), new Class[]{clazz}, new RpcInvocationHandler());
        return o;
    }

    @Override
    public Class<?> getObjectType() {
        return clazz;
    }
}
